//
//  SectionViewController.m
//  PlayDAs
//
//  Created by 周莹 on 15/12/15.
//  Copyright © 2015年 周莹. All rights reserved.
//
#import "TSPopoverController.h"
#import "TSActionSheet.h"
#import "SectionViewController.h"
#import "PopoverView.h"
#import "CustomButton.h"
// 屏幕_宽_高
#define SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT  ([[UIScreen mainScreen] bounds].size.height)

#define IPHONE6_W 375.0f
#define IPHONE6_H 667.0f

// 控件缩放比例
#define SCALE_WIDTH(w) (SCREEN_WIDTH/375.0*w)

// 如果是iPhone4
#define RECTFIX_WIDTH(a) (IS_IPHONE4 ? a : SCALE_WIDTH(a))
#define RECTFIX_HEIGHT(a) (IS_IPHONE4 ? a : SCALE_HEIGHT(a))

// 左右两边的间距
#define MARGIN_1 10.0f

// 男女之间的间距
#define MARGIN_2 5.0f
// 男女之间的间距
#define MARGIN_3 MARGIN_2+w+20

// 第一个按钮的宽
#define BUTTON_1_W 95.0f

// 按钮的高
#define BUTTON_H 30.0f

// 按钮的Y值
#define BUTTON_Y  18.0f
#define LeftB   @"fenxiang"

@interface SectionViewController ()

@end

@implementation SectionViewController

- (void)viewDidLoad {
    [self creat];
    self.title = @"收藏";
    [super viewDidLoad];
    UIButton *rightB = [UIButton buttonWithType:UIButtonTypeCustom];
    rightB.titleLabel.text = @"我";
    rightB.frame = CGRectMake(0, 0, 30, 30);
    [rightB setBackgroundImage:[UIImage imageNamed:LeftB] forState:UIControlStateNormal];
    [rightB addTarget:self action:@selector(showActionSheet:forEvent:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightB];
    // Do any additional setup after loading the view from its nib.
}
-(void)leftBDidPOP{
    
    CGPoint point = CGPointMake(self.view.frame.size.height, self.view.frame.size.width/5);
    NSArray *titles = @[@"分享", @"扫一扫", @"帮助",@"反馈"];
    PopoverView *pop = [[PopoverView alloc] initWithPoint:point titles:titles images:nil];
    pop.selectRowAtIndex = ^(NSInteger index){
        NSLog(@"select index:%ld", (long)index);
    };
    [pop show];
    
    
    
}
-(void) showActionSheet:(id)sender forEvent:(UIEvent*)event
{
    
    
    TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@"类别"];
    
    [actionSheet addButtonWithTitle:@"分享" block:^{
        //        EmpViewController  *e = [[EmpViewController  alloc] init];
        //        [self.navigationController  pushViewController:e  animated:YES];
    }];
    [actionSheet addButtonWithTitle:@"扫一扫" block:^{
        //        FacViewController  *n = [[FacViewController  alloc] init];
        //        [self.navigationController  pushViewController:n animated:YES];
    }];
    [actionSheet addButtonWithTitle:@"帮助" block:^{
        //        PdViewController  *p = [[PdViewController  alloc] init];
        //        [self.navigationController  pushViewController:p  animated:YES];
    }];
    
    [actionSheet addButtonWithTitle:@"反馈de" block:^{
        //        PdViewController  *p = [[PdViewController  alloc] init];
        //        [self.navigationController  pushViewController:p  animated:YES];
    }];
    actionSheet.cornerRadius = 5;
    
    [actionSheet showWithTouch:event];
    
    
    
    
}




-(void)creat{
    self.scrollView = [[UIScrollView alloc]init];
    
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT );
   // self.scrollView.backgroundColor = RGBA(238, 239, 242, 1);
    
    self.scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
    
    [self.view addSubview:self.scrollView];
    


    CGFloat  lableW = SCALE_WIDTH(55);
    CGFloat  lableH = SCALE_WIDTH(80);
    CGFloat  lableX = MARGIN_1;
    CGFloat  lableY = BUTTON_Y;
    

    
    //CGRectMake(lableX, lableY, lableW, lableH);
   
    
    CGRect customFrame = CGRectMake(lableX, lableY, lableW, lableH);
    
    
    // 创建按钮
    self.button1 = [[CustomButton alloc] initWithFrame:customFrame OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
        
    }];
    
        
    // 把按钮添加进父视图
    [self.view addSubview:self.button1];

    
    
    
    
    
  //  CGFloat w = (SCREEN_WIDTH - (MARGIN_1 * 2) - (MARGIN_2 * 3) - btn1W) / 3;

    
    
    
   
    
    CGFloat  w = (SCREEN_WIDTH -(MARGIN_1  * 2)-(MARGIN_2 * 5)- lableW)/5;
    
    CGFloat btn2W = w;
    CGFloat btn2H = lableH;
    CGFloat btn2X = CGRectGetMaxX(self.button1.frame) + MARGIN_2;
    CGFloat btn2Y = BUTTON_Y;
    //CGRectMake(btn2X, btn2Y, btn2W, btn2H)
    
    
    
    CGRect customFrame2 = CGRectMake(btn2X, btn2Y, btn2W, btn2H);
    // 创建按钮
    self.button2 = [[CustomButton alloc] initWithFrame:customFrame2 OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
    }];
    // 把按钮添加进父视图
    [self.scrollView addSubview:self.button2];
    
    
    
    
    
    //CGRectMake(btn3X, btn3Y, btn3W, btn3H);
    
    CGFloat btn3W = w;
    CGFloat btn3H = lableH;
    CGFloat btn3X = CGRectGetMaxX(self.button2.frame) + MARGIN_2;
    CGFloat btn3Y = BUTTON_Y;
    CGRect customFrame3 = CGRectMake(btn3X, btn3Y, btn3W, btn3H);
    // 创建按钮
    self.button3 = [[CustomButton alloc] initWithFrame:customFrame3 OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
    }];
    // 把按钮添加进父视图
    [self.scrollView addSubview:self.button3];
    

    
    
    //CGRectMake(btn4X, btn4Y, btn4W, btn4H);
    
    CGFloat btn4W = w;
    CGFloat btn4H = lableH;
    CGFloat btn4X = CGRectGetMaxX(self.button3.frame) + MARGIN_2;
    CGFloat btn4Y = BUTTON_Y;
    
    CGRect customFrame4 = CGRectMake(btn4X, btn4Y, btn4W, btn4H);
    // 创建按钮
    self.button4 = [[CustomButton alloc] initWithFrame:customFrame4 OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
    }];
    // 把按钮添加进父视图
    [self.scrollView addSubview:self.button4];
    
    

    //CGRectMake(btn5X, btn5Y, btn5W, btn5H);

    CGFloat btn5W = w;
    CGFloat btn5H = lableH;
    CGFloat btn5X = CGRectGetMaxX(self.button4.frame) + MARGIN_2;
    CGFloat btn5Y = BUTTON_Y;
    
    
    CGRect customFrame5 = CGRectMake(btn5X, btn5Y, btn5W, btn5H);
    // 创建按钮
    self.button5 = [[CustomButton alloc] initWithFrame:customFrame5 OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
    }];
    // 把按钮添加进父视图
    [self.scrollView addSubview:self.button5];
    
    
    
    //CGRectMake(btn6X, btn6Y, btn6W, btn6H);
    CGFloat btn6W = w;
    CGFloat btn6H = lableH;
    CGFloat btn6X = CGRectGetMaxX(self.button5.frame) + MARGIN_2;
    CGFloat btn6Y = BUTTON_Y;
    
    CGRect customFrame6 = CGRectMake(btn6X, btn6Y, btn6W, btn6H);

    // 创建按钮
    self.button6 = [[CustomButton alloc] initWithFrame:customFrame6 OFFImageName:@"daijia" ONImageName:@"fangchejinrong" ClickCall:^{
        
        /// 点击按钮时回调
        /// 可以这里做事情
        NSLog(@"自定义按钮回调了！！！");
    }];
    // 把按钮添加进父视图
    [self.scrollView addSubview:self.button6];
    

    
    
    
    
    

}

//点击事件
-(void)ButtonActon1:(UIButton *)sender{



}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
